package com.itsm.sheet.service.impl;

import com.itsm.common.sheet.JzsyEventSheetProcessDto;
import com.itsm.common.sheet.TransferSheetDto;
import com.itsm.sheet.entity.JzsyEventSheet;
import com.itsm.sheet.entity.JzsyEventSheetProcess;
import com.itsm.sheet.mapper.JzsyEventSheetMapper;
import com.itsm.sheet.mapper.JzsyEventSheetProcessMapper;
import com.itsm.sheet.service.IJzsyEventSheetProcessService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class JzsyEventSheetProcessServiceImpl implements IJzsyEventSheetProcessService {

    @Autowired
    private JzsyEventSheetProcessMapper jzsyEventSheetProcessMapper;

    @Autowired
    private JzsyEventSheetMapper jzsyEventSheetMapper;


    public JzsyEventSheetProcess claimSheet(JzsyEventSheetProcessDto jzsyEventSheetProcessDto){
        //修改工单状态
        JzsyEventSheet jzsyEventSheet = jzsyEventSheetMapper.selectById(jzsyEventSheetProcessDto.getSheetId());
        jzsyEventSheet.setSheetStatus("DOING");
        jzsyEventSheetMapper.updateById(jzsyEventSheet);
        //
        JzsyEventSheetProcess jzsyEventSheetProcess = new JzsyEventSheetProcess();
        BeanUtils.copyProperties(jzsyEventSheetProcessDto,jzsyEventSheetProcess);
        jzsyEventSheetProcessMapper.insert(jzsyEventSheetProcess);
        return jzsyEventSheetProcess;
    }

    public JzsyEventSheetProcess transferSheet(TransferSheetDto transferSheetDto){
        JzsyEventSheetProcess jzsyEventSheetProcess = jzsyEventSheetProcessMapper.selectById(transferSheetDto.getSheepProcessId());
        jzsyEventSheetProcess.setProblemReason(transferSheetDto.getProblemReason());
        jzsyEventSheetProcess.setResolvent(transferSheetDto.getResolvent());
        jzsyEventSheetProcess.setAnswer(transferSheetDto.getAnswer());
        jzsyEventSheetProcess.setResolutionTime(transferSheetDto.getResolutionTime());
        jzsyEventSheetProcessMapper.updateById(jzsyEventSheetProcess);

        JzsyEventSheetProcess newProcess = new JzsyEventSheetProcess();
        newProcess.setSheetId(jzsyEventSheetProcess.getSheetId());
        newProcess.setSheetCode(jzsyEventSheetProcess.getSheetCode());
        newProcess.setSheetTitle(jzsyEventSheetProcess.getSheetTitle());
        newProcess.setProcessUser(transferSheetDto.getReceiverId());
        jzsyEventSheetProcessMapper.insert(newProcess);

        return newProcess;
    }
    public JzsyEventSheetProcess upgradeSheet(TransferSheetDto transferSheetDto){
        JzsyEventSheetProcess jzsyEventSheetProcess = jzsyEventSheetProcessMapper.selectById(transferSheetDto.getSheepProcessId());


        jzsyEventSheetProcessMapper.updateById(jzsyEventSheetProcess);
        return jzsyEventSheetProcess;
    }
}
